home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / BrainRulers / Source / DragPSView.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  62 lines

  1. // A simple view class that responds to mouseDown event by 
  2. // opening a stream and sending a message to a 'streamProvider'
  3. // to draw postscript code into the stream.  It then writes the
  4. // stream back to the file (DRAGGEDFILENAME) and invokes the view
  5. // method dragFile:fromRect:slideBack:event:
  6. // You must connect the streamProvider outlet to an object that 
  7. // responds to writeToStream: by writing the contents of the file
  8. // represented by the icon to the given stream.
  9. // DragPSView.h provides an interface to a 'streamProvider'
  10. // category (of the Object class) with this method.
  11. // Note: This class does not remove DRAGGEDFILENAME.
  12. // DragPSView composites an image (IMAGENAME) to draw itself.
  13.  
  14. #import "DragPSView.h"
  15. #import <appkit/NXImage.h>
  16. #import <sys/file.h>
  17. #import <appkit/nextstd.h>        // imports math.h,stdio.h,libc.h
  18.  
  19. @implementation DragPSView
  20.  
  21. - drawSelf:(NXRect *)rects :(int)rectCount
  22. {
  23.     NXPoint    point;
  24.     NXImage *theImage;
  25.     
  26.     point.x = 0.0;
  27.     point.y = 0.0;
  28.     theImage = [NXImage findImageNamed:IMAGENAME];
  29.     [theImage composite:NX_SOVER toPoint:&point];
  30.     
  31.     return self;
  32. }
  33.  
  34. - mouseDown:(NXEvent *)theEvent
  35. {
  36.     int    fd;
  37.     NXStream *stream;
  38.     NXRect iconRect;
  39.     
  40.     fd = open(DRAGGEDFILENAME, O_CREAT | O_WRONLY | O_TRUNC, 0666);
  41.     stream = NXOpenFile(fd, NX_WRITEONLY);
  42.  
  43.     [streamProvider writeToStream:(NXStream *)stream];
  44.     // printViewToStream: is a method that writes postscript
  45.     // code to the given stream.
  46.  
  47.     NXFlush(stream);
  48.     NXClose(stream);
  49.     close(fd);
  50.  
  51.     NXSetRect(&iconRect, (NXCoord) 0, (NXCoord) 0, (NXCoord) 48, (NXCoord) 48);
  52.  
  53.     [self dragFile:DRAGGEDFILENAME
  54.         fromRect:(NXRect *)&iconRect
  55.         slideBack:(BOOL) YES
  56.         event:(NXEvent *)theEvent];
  57.  
  58.     return self;
  59. }
  60.  
  61. @end
  62.